Enable trim and AOT analyzers for selected library tests#128355
Enable trim and AOT analyzers for selected library tests#128355Copilot wants to merge 9 commits into
Conversation
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/5977beb1-58f4-4a75-9a1c-02ff1bb17294 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/5977beb1-58f4-4a75-9a1c-02ff1bb17294 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
|
Tagging subscribers to this area: @dotnet/area-infrastructure-libraries |
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/5a0b0c7b-d13e-4936-8392-ff08d859bc72 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/5a0b0c7b-d13e-4936-8392-ff08d859bc72 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
|
|
||
| // Try to get the StateMachine field from the AsyncStateMachineBox<>. If we can't, | ||
| // just print out the details we can and bail. | ||
| #pragma warning disable IL2075 |
There was a problem hiding this comment.
Now that we're using runtime-async I wonder if this is just dead code
There was a problem hiding this comment.
Agreed, this looks like it will no longer do what is says with runtime async. We should delete GetStateMachineData.Describe method and the callers.
There was a problem hiding this comment.
Addressed in 7d17a32 by deleting GetStateMachineData.Describe and removing its remaining caller.
There was a problem hiding this comment.
Addressed in 7d17a32 by deleting GetStateMachineData.Describe and updating the Watchdog caller.
There was a problem hiding this comment.
Already addressed in 7d17a32 by deleting GetStateMachineData.Describe and removing its remaining caller.
|
|
||
| // Try to get the StateMachine field from the AsyncStateMachineBox<>. If we can't, | ||
| // just print out the details we can and bail. | ||
| #pragma warning disable IL2075 |
There was a problem hiding this comment.
Agreed, this looks like it will no longer do what is says with runtime async. We should delete GetStateMachineData.Describe method and the callers.
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/087bc9c5-a2a7-4eea-becd-4a9625ddce15 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/087bc9c5-a2a7-4eea-becd-4a9625ddce15 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
MichalStrehovsky
left a comment
There was a problem hiding this comment.
@dotnet/illink could someone have a look please? From my side the main open question is what to do with #128355 (comment). I asked copilot to delete it. Maybe we could also just pragma suppress it and file a bug on the networking team to figure out what they want to do with it.
There was a problem hiding this comment.
Pull request overview
This PR enables trim/AOT analyzers for a set of library test projects by removing project-level analyzer disables and addressing resulting warnings with targeted code changes (e.g., analyzer-friendly APIs) and narrowly-scoped suppressions/annotations at test-only reflection/dynamic-code sites.
Changes:
- Removed project-level
EnableTrimAnalyzer/EnableAotAnalyzerdisables from selected test projects. - Replaced broad suppressions with targeted fixes,
Requires*annotations, and narrow#pragma warning disable/restorescopes where reflection/dynamic code is test-required. - Updated a few tests/helpers to be more analyzer-friendly (e.g.,
Enum.GetValues<TEnum>(),DiagnosticMethodInfo, LINQ conversions, and source-project references where needed).
Reviewed changes
Copilot reviewed 52 out of 52 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Threading.RateLimiting/tests/System.Threading.RateLimiting.Tests.csproj | Re-enables trim analyzer and adjusts test project reference settings. |
| src/libraries/System.Threading.RateLimiting/tests/PartitionedRateLimiterTests.cs | Updates calls to reflection-based helper with explicit generic arguments. |
| src/libraries/System.Threading.RateLimiting/tests/Infrastructure/Utils.cs | Refactors reflection helper used to invoke DefaultPartitionedRateLimiter heartbeat under analyzers. |
| src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn4.4.Unit.Tests.csproj | Re-enables trim analyzer for Roslyn 4.4 source-gen unit tests. |
| src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn3.11.Unit.Tests.csproj | Re-enables trim analyzer for Roslyn 3.11 source-gen unit tests. |
| src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorIncrementalTests.cs | Adds targeted suppressions for reflection-heavy structural equality checks. |
| src/libraries/System.Security.Cryptography.Pkcs/tests/System.Security.Cryptography.Pkcs.Tests.csproj | Re-enables AOT analyzer for PKCS tests. |
| src/libraries/System.Security.Cryptography.Pkcs/tests/RecipientInfoCollectionTests.cs | Adds narrow IL3050 suppression around non-zero-lower-bound array creation. |
| src/libraries/System.Security.Cryptography.Pkcs/tests/CryptographicAttributeObjectCollectionTests.cs | Adds narrow IL3050 suppression around non-zero-lower-bound array creation. |
| src/libraries/System.Security.Cryptography.Pkcs/tests/CmsRecipientCollectionTests.cs | Adds narrow IL3050 suppression around non-zero-lower-bound array creation. |
| src/libraries/System.Runtime/tests/System.Threading.Tasks.Extensions.Tests/System.Threading.Tasks.Extensions.Tests.csproj | Re-enables trim analyzer for task extensions tests. |
| src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeInterpreted/System.Runtime.ReflectionInvokeInterpreted.Tests.csproj | Re-enables trim analyzer for reflection invoke-interpreted tests. |
| src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeEmit/System.Runtime.ReflectionInvokeEmit.Tests.csproj | Re-enables trim analyzer for reflection invoke-emit tests. |
| src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/BindingFlagsDoNotWrap.cs | Adds narrow suppression for reflection pattern warning during Assembly.CreateInstance tests. |
| src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj | Re-enables trim analyzer for RuntimeInformation tests. |
| src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/DescriptionNameTests.cs | Adds narrow suppression for reflection-based informational logging. |
| src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/System.Reflection.CoreCLR.Tests.csproj | Re-enables trim analyzer for System.Reflection CoreCLR tests. |
| src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/AssemblyTests.cs | Adds narrow suppressions for AssemblyLoadContext.LoadFromStream trimming warnings. |
| src/libraries/System.Runtime/tests/System.Buffers.Tests/System.Buffers.Tests.csproj | Re-enables trim analyzer for System.Buffers tests. |
| src/libraries/System.Runtime/tests/System.Buffers.Tests/ArrayPool/CollectionTests.cs | Adds narrow suppression around known-broken private reflection access in a stress test. |
| src/libraries/System.Runtime.Serialization.Primitives/tests/System/Runtime/Serialization/InvalidDataContractExceptionTests.cs | Annotates BinaryFormatter serialization test with RequiresDynamicCode/RequiresUnreferencedCode. |
| src/libraries/System.Runtime.Serialization.Primitives/tests/System.Runtime.Serialization.Primitives.Tests.csproj | Re-enables trim/AOT analyzers for serialization primitives tests. |
| src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System/Runtime/InteropServices/Marshal/MarshalComDisabledTests.cs | Adds narrow suppression for COM-disabled reflection-only API usage. |
| src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System.Runtime.InteropServices.ComDisabled.Tests.csproj | Re-enables trim analyzer for COM-disabled interop unit tests. |
| src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComInterfaceGenerator.Unit.Tests.csproj | Re-enables trim analyzer for ComInterfaceGenerator unit tests. |
| src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs | Adds narrow suppression around reflection-based Type.GetType(...) usage in generated snippets. |
| src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj | Re-enables trim analyzer for WebSockets client tests. |
| src/libraries/System.Net.WebSockets.Client/tests/CloseTest.Loopback.cs | Adds narrow suppressions around reflection-based activation in loopback test. |
| src/libraries/System.Net.WebProxy/tests/WebProxyTest.cs | Replaces ArrayList-to-array conversion with LINQ-based conversion to avoid AOT warnings. |
| src/libraries/System.Net.WebProxy/tests/System.Net.WebProxy.Tests.csproj | Re-enables AOT analyzer for WebProxy tests. |
| src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj | Re-enables AOT analyzer for System.Net.Security functional tests. |
| src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamNegotiatedCipherSuiteTest.cs | Uses Enum.GetValues<TEnum>() to avoid dynamic enum array creation warnings. |
| src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj | Re-enables trim analyzer for QUIC functional tests. |
| src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs | Adds trim annotations and targeted suppression for reflection-based member reset helper. |
| src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj | Re-enables AOT analyzer for System.Net.Mail functional tests. |
| src/libraries/System.Net.Mail/tests/Functional/MailMessageTest.cs | Adds narrow IL3050 suppression around reflection-based private SendAsync invocation. |
| src/libraries/System.Net.Http/tests/FunctionalTests/Watchdog.cs | Removes state-machine diagnostic printing and adjusts watchdog timer behavior. |
| src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj | Re-enables trim analyzer for WinHttpHandler unit tests. |
| src/libraries/System.Management/tests/System.Management.Tests.csproj | Re-enables trim/AOT analyzers for System.Management tests. |
| src/libraries/System.IO.Packaging/tests/System.IO.Packaging.Tests.csproj | Re-enables AOT analyzer for System.IO.Packaging tests. |
| src/libraries/System.IO.Packaging/tests/PartPieceTests.cs | Adds narrow IL3050 suppression around MakeGenericType used in reflection-heavy test logic. |
| src/libraries/System.DirectoryServices/tests/System.DirectoryServices.Tests.csproj | Re-enables trim analyzer for System.DirectoryServices tests. |
| src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/SkippableDependencyInjectionSpecificationTests.cs | Switches to DiagnosticMethodInfo to avoid trim warnings from StackFrame.GetMethod(). |
| src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/Microsoft.Extensions.DependencyInjection.ExternalContainers.Tests.csproj | Re-enables trim analyzer for external container DI tests. |
| src/libraries/Microsoft.Extensions.Configuration/tests/Microsoft.Extensions.Configuration.Tests.csproj | Re-enables trim/AOT analyzers for configuration tests. |
| src/libraries/Microsoft.Extensions.Configuration/tests/ConfigurationProviderTestBase.cs | Adds narrow suppressions around reflection-based binder usage in tests. |
| src/libraries/Microsoft.Extensions.Configuration.Json/tests/Microsoft.Extensions.Configuration.Json.Tests.csproj | Re-enables trim/AOT analyzers for JSON configuration tests. |
| src/libraries/Microsoft.Extensions.Configuration.Ini/tests/Microsoft.Extensions.Configuration.Ini.Tests.csproj | Re-enables trim/AOT analyzers for INI configuration tests. |
| src/libraries/Microsoft.Extensions.Configuration.CommandLine/tests/Microsoft.Extensions.Configuration.CommandLine.Tests.csproj | Re-enables trim/AOT analyzers for command-line configuration tests. |
| src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/GeneratorTests.Incremental.cs | Adds narrow IL2026 suppression around structural reflection equality helper. |
| src/libraries/Common/tests/System/Threading/Tasks/GetStateMachineData.cs | Removes reflection-based Describe logic; keeps awaitable box capture helper. |
| src/libraries/Common/tests/SourceGenerators/GeneratorTestHelpers.cs | Adds RequiresUnreferencedCode annotation to reflection-based structural equality helper. |
Comments suppressed due to low confidence (1)
src/libraries/System.Net.Http/tests/FunctionalTests/Watchdog.cs:40
- Watchdog._box is assigned in UnsafeOnCompleted but is no longer read anywhere after the GetStateMachineData.Describe removal. This is likely to trigger CS0414 (assigned but its value is never used) under warnings-as-errors. Remove the field/assignment (or otherwise consume the value) to avoid introducing a build warning.
internal class Watchdog : ICriticalNotifyCompletion
{
private object _box;
private Watchdog() { }
public static Watchdog CreateAsync()
=> new Watchdog();
public IDisposable GetResult()
=> new WatchdogImpl();
public Watchdog GetAwaiter() => this;
public bool IsCompleted => false;
public void OnCompleted(Action continuation) => UnsafeOnCompleted(continuation);
public void UnsafeOnCompleted(Action continuation)
{
_box = continuation.Target;
Task.Run(continuation);
}
|
@copilot build breaks For the ManagementObjectTests.cs occurence, mark the method as For the DirectoryServicesTests.cs, suppress the warning using |
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/5e49e977-7ef9-4b3f-ba25-f076d020cb7e Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
|
Build breaks in the .NET framework build (TargetFramework=net481). Add ifdef for the Also a build break on Windows x64: For this, propagate the DynamicallyAccessedMembers annotations from the called method to the calling methods T. |
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/798bad8f-5f09-4037-886d-e162a23c8e96 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
... Fixed in ea6ff58. I added the net481 fallback around |
Description
Several library test projects suppressed trim/AOT analyzer warnings by disabling the analyzers at the project level. This change enables the analyzers for the selected test projects where appropriate and replaces broad suppressions with targeted fixes or narrow warning pragmas at known test-only reflection and dynamic-code sites.
dotnet/runtime#126862analyzer-disable blocks from the selected test projects, while leavingMicrosoft.Extensions.HostFactoryResolver.Testsdisabled for separate follow-up because enabling it would require product changes.DiagnosticMethodInfo,Enum.GetValues<TEnum>(), LINQ-based collection conversion, and source-project references where applicable.net481test builds.System.Threading.RateLimiting.Teststo reference the source project withSkipUseReferenceAssembly="true"and avoid local reflection suppressions.DynamicallyAccessedMembersannotations through the WinHttpHandler test marshal shim.GetStateMachineData.Describediagnostic code and its remaining caller now that it no longer works with runtime async.#pragma warning disable/restorescopes only for remaining emitted IL warnings that require reflection, dynamic code, or unsupported trim/AOT analysis patterns.